<template>
  <div class="app-container">
    <uc-table url="admin/statis/monthReportStatis" ref="ucTable" name="月度报告" table-border pageable
              :search-form="searchForm">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item label="月份">
            <el-date-picker
                v-model="searchForm.monthRange"
                type="monthrange"
                value-format="yyyy-MM"
                range-separator="至"
                start-placeholder="开始月份"
                end-placeholder="结束月份">
            </el-date-picker>
          </el-form-item>
          <el-form-item v-if="enterPriseHidden">
            <el-select v-model="searchForm.enterpriseId" placeholder="请选择所属主体" clearable @clear="clearInput()">
              <el-option v-for="(item,index) in enterpriseList" :key="index" :value="item.ucId"
                         :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <!--搜索按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column prop="month" label="月份"></el-table-column>
        <el-table-column prop="enterpriseName" label="主体"></el-table-column>
        <el-table-column label="消防隐患" align="center">
          <el-table-column prop="dangerNum" label="隐患总数"></el-table-column>
          <el-table-column prop="dangerFinishNum" label="整改完成"></el-table-column>
        </el-table-column>
        <el-table-column label="火情报警" align="center">
          <el-table-column prop="fireReportNum" label="报警总数"></el-table-column>
          <el-table-column prop="realFireNum" label="真实火情"></el-table-column>
          <el-table-column prop="fakeFireNum" label="误报火情"></el-table-column>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";

export default {
  name: "monthReport",
  components: {UcTable},
  data() {
    return {
      searchForm: {
        monthRange: [],
        enterpriseId: null
      },
      enterpriseList: []
    }
  },
  computed: {
    enterPriseHidden() {
      let roleCode = this.$store.getters.roleCode;
      return roleCode == "ADMIN" || roleCode == "XT-ADMIN" || roleCode == "ZD-ADMIN" || roleCode == "DD-ADMIN" || roleCode == "JW-ADMIN"
    }
  },
  created() {
    this.getInEnterpriseDominantList()
  },
  methods: {
    //搜索
    handleSearch() {
      this.$refs.ucTable.getTableData(1)
    },
    //清空主体选项
    clearInput() {
      this.searchForm.enterpriseId = null
      this.handleSearch()
    },
    //获取安全主体
    getInEnterpriseDominantList() {
      getInEnterpriseDominantList({dominantType: 6, deleted: false}).then(res => {
        this.enterpriseList = res.data
      })
    },
  }
}
</script>

<style>

</style>
